<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="区域" prop="area">
        <el-input
          v-model="queryParams.area"
          placeholder="请输入区域"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option label="可用" value="available" />
          <el-option label="预订" value="booked" />
          <el-option label="发台" value="fatai" />
          <el-option label="使用" value="inuse" />
          <el-option label="结账" value="checkout" />
          <el-option label="清洁" value="clean" />
          <el-option label="联台" value="union" />
        </el-select>
      </el-form-item>
      <el-form-item label="开始时间" prop="startTime">
        <el-date-picker
          v-model="queryParams.startTime"
          type="datetime"
          placeholder="选择开始时间"
          value-format="yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
          format="yyyy-MM-dd HH:mm:ss"
          clearable
        />
      </el-form-item>
      <el-form-item label="结束时间" prop="endTime">
        <el-date-picker
          v-model="queryParams.endTime"
          type="datetime"
          placeholder="选择结束时间"
          value-format="yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
          format="yyyy-MM-dd HH:mm:ss"
          clearable
        />
      </el-form-item>
      <el-form-item label="备用字段 ee" prop="ee">
        <el-input
          v-model="queryParams.ee"
          placeholder="请输入备用字段 ee"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备用字段 ff" prop="ff">
        <el-input
          v-model="queryParams.ff"
          placeholder="请输入备用字段 ff"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="价格" prop="price">
        <el-input-number
          v-model="queryParams.price"
          placeholder="请输入价格"
          :precision="2"
          :step="0.1"
          :min="0"
          :controls="false"
          clearable
          @change="handlePriceChange"
          @clear="handlePriceClear"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:room:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:room:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:room:remove']"
        >删除</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:room:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="roomList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="房间号" align="center" prop="id" />
      <el-table-column label="房间名" align="center" prop="cc" />
<!--      <el-table-column label="区域" align="center" prop="area" />-->
      <el-table-column label="价格" align="center" prop="price" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <el-tag :type="getStatusType(scope.row.status)">
            {{ getStatusLabel(scope.row.status) }}
          </el-tag>
        </template>
      </el-table-column>
<!--      <el-table-column label="开始时间" align="center" prop="startTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="结束时间" align="center" prop="endTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="预订业务员组" align="center" prop="groupName">
        <template slot-scope="scope">
          {{ getBusinessUserNames(scope.row.groupName) }}
        </template>
      </el-table-column>
      <el-table-column label="用途" align="center" prop="purpose" />
      <el-table-column label="订房人ID" align="center" prop="bookerId" />
      <el-table-column label="服务员ID" align="center" prop="serviceStaffId" />
      <el-table-column label="DJ ID" align="center" prop="djId" />
<!--      <el-table-column label="订房人进房次数" align="center" prop="bookerEntryCount" />-->
<!--      <el-table-column label="服务员进房次数" align="center" prop="serviceStaffEntryCount" />-->
<!--      <el-table-column label="DJ进房次数" align="center" prop="djEntryCount" />-->
      <el-table-column label="总金额" align="center" prop="totalAmount" />
      <el-table-column label="折扣" align="center" prop="discount" />
      <el-table-column label="服务员工资支付方式" align="center" prop="serviceStaffPayment">
        <template slot-scope="scope">
          {{ getPaymentLabel(scope.row.serviceStaffPayment) }}
        </template>
      </el-table-column>
      <el-table-column label="DJ工资支付方式" align="center" prop="djPayment">
        <template slot-scope="scope">
          {{ getPaymentLabel(scope.row.djPayment) }}
        </template>
      </el-table-column>
      <el-table-column label="业务员工资支付方式" align="center" prop="salespersonPayment">
        <template slot-scope="scope">
          {{ getPaymentLabel(scope.row.salespersonPayment) }}
        </template>
      </el-table-column>
<!--      <el-table-column label="备用字段 ee" align="center" prop="ee" />-->
<!--      <el-table-column label="备用字段 ff" align="center" prop="ff" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:room:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:room:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDetail(scope.row)"
            v-hasPermi="['system:room:edit']"
          >房间详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-refresh"
            @click="handleFlipTable(scope.row)"
            v-hasPermi="['system:room:edit']"
          >翻台</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改房间信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">

        <el-form-item label="房间名" prop="cc" required>
          <el-input v-model="form.cc" placeholder="请输入房间名" />
        </el-form-item>
        <el-form-item label="区域" prop="area">
          <el-input v-model="form.area" placeholder="请输入区域" />
        </el-form-item>
        <el-form-item label="价格" prop="price">
          <el-input-number
            v-model="form.price"
            placeholder="请输入价格"
            :precision="2"
            :step="0.1"
            :min="0"
          />
        </el-form-item>

        <el-form-item label="状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择状态">
            <el-option label="可用" value="available" />
            <el-option label="预订" value="booked" />
            <el-option label="发台" value="fatai" />
            <el-option label="使用" value="inuse" />
            <el-option label="结账" value="checkout" />
            <el-option label="清洁" value="clean" />
            <el-option label="联台" value="union" />
          </el-select>
        </el-form-item>
        <el-form-item label="开始时间" prop="startTime">
          <el-date-picker
            v-model="form.startTime"
            type="datetime"
            placeholder="选择开始时间"
            value-format="yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
            format="yyyy-MM-dd HH:mm:ss"
          />
        </el-form-item>
        <el-form-item label="结束时间" prop="endTime">
          <el-date-picker
            v-model="form.endTime"
            type="datetime"
            placeholder="选择结束时间"
            value-format="yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
            format="yyyy-MM-dd HH:mm:ss"
          />
        </el-form-item>
        <el-form-item label="预订业务员组" prop="groupName">
          <el-select
            v-model="selectedBusinessUsers"
            multiple
            filterable
            placeholder="请选择预订业务员"
            @change="handleGroupNameChange"
          >
            <el-option
              v-for="item in businessUsers"
              :key="item.userId"
              :label="item.userName"
              :value="item.userId"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="用途" prop="purpose">
          <el-input v-model="form.purpose" placeholder="请输入用途" />
        </el-form-item>
        <el-form-item label="订房人ID" prop="bookerId">
          <el-input v-model="form.bookerId" placeholder="请输入订房人ID" />
        </el-form-item>
        <el-form-item label="服务员ID" prop="serviceStaffId">
          <el-input v-model="form.serviceStaffId" placeholder="请输入服务员ID" />
        </el-form-item>
        <el-form-item label="DJ ID" prop="djId">
          <el-input v-model="form.djId" placeholder="请输入DJ ID" />
        </el-form-item>

        <el-form-item label="订房人进房次数" prop="bookerEntryCount">
          <el-input-number v-model="form.bookerEntryCount" :min="0" placeholder="请输入订房人进房次数" />
        </el-form-item>
        <el-form-item label="服务员进房次数" prop="serviceStaffEntryCount">
          <el-input-number v-model="form.serviceStaffEntryCount" :min="0" placeholder="请输入服务员进房次数" />
        </el-form-item>
        <el-form-item label="DJ进房次数" prop="djEntryCount">
          <el-input-number v-model="form.djEntryCount" :min="0" placeholder="请输入DJ进房次数" />
        </el-form-item>
        <el-form-item label="总金额" prop="totalAmount">
          <el-input-number v-model="form.totalAmount" :precision="2" :step="0.1" :min="0" placeholder="请输入总金额" />
        </el-form-item>
        <el-form-item label="折扣" prop="discount">
          <el-input-number v-model="form.discount" :precision="2" :step="0.1" :min="0" placeholder="请输入折扣" />
        </el-form-item>
        <el-form-item label="服务员工资支付方式" prop="serviceStaffPayment">
          <el-select v-model="form.serviceStaffPayment" placeholder="请选择服务员工资支付方式">
            <el-option label="现金" value="现金" />
            <el-option label="转账" value="转账" />
            <el-option label="自付" value="自付" />
          </el-select>
        </el-form-item>
        <el-form-item label="DJ工资支付方式" prop="djPayment">
          <el-select v-model="form.djPayment" placeholder="请选择DJ工资支付方式">
            <el-option label="现金" value="现金" />
            <el-option label="转账" value="转账" />
            <el-option label="自付" value="自付" />
          </el-select>
        </el-form-item>
        <el-form-item label="业务员工资支付方式" prop="salespersonPayment">
          <el-select v-model="form.salespersonPayment" placeholder="请选择业务员工资支付方式">
            <el-option label="现金" value="现金" />
            <el-option label="转账" value="转账" />
            <el-option label="自付" value="自付" />
          </el-select>
        </el-form-item>

        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入备注" />
        </el-form-item>
<!--        <el-form-item label="备用字段 ee" prop="ee">-->
<!--          <el-input v-model="form.ee" placeholder="请输入备用字段 ee" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="备用字段 ff" prop="ff">-->
<!--          <el-input v-model="form.ff" placeholder="请输入备用字段 ff" />-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="title" :visible.sync="open1" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">

        <el-form-item label="房间名" prop="cc" required>
          <el-input v-model="form.cc" placeholder="请输入房间名" />
        </el-form-item>
        <el-form-item label="区域" prop="area">
          <el-input v-model="form.area" placeholder="请输入区域" />
        </el-form-item>
        <el-form-item label="价格" prop="price">
          <el-input-number
            v-model="form.price"
            placeholder="请输入价格"
            :precision="2"
            :step="0.1"
            :min="0"
          />
        </el-form-item>

        <el-form-item label="状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择状态">
            <el-option label="可用" value="available" />
            <el-option label="预订" value="booked" />
            <el-option label="发台" value="fatai" />
            <el-option label="使用" value="inuse" />
            <el-option label="结账" value="checkout" />
            <el-option label="清洁" value="clean" />
            <el-option label="联台" value="union" />
          </el-select>
        </el-form-item>
        <el-form-item label="开始时间" prop="startTime">
          <el-date-picker
            v-model="form.startTime"
            type="datetime"
            placeholder="选择开始时间"
            value-format="yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
            format="yyyy-MM-dd HH:mm:ss"
          />
        </el-form-item>
        <el-form-item label="结束时间" prop="endTime">
          <el-date-picker
            v-model="form.endTime"
            type="datetime"
            placeholder="选择结束时间"
            value-format="yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
            format="yyyy-MM-dd HH:mm:ss"
          />
        </el-form-item>
        <el-form-item label="预订业务员组" prop="groupName">
          <el-select
            v-model="selectedBusinessUsers"
            multiple
            filterable
            placeholder="请选择预订业务员"
            @change="handleGroupNameChange"
          >
            <el-option
              v-for="item in businessUsers"
              :key="item.userId"
              :label="item.userName"
              :value="item.userId"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="用途" prop="purpose">
          <el-input v-model="form.purpose" placeholder="请输入用途" />
        </el-form-item>
        <el-form-item label="订房人ID" prop="bookerId">
          <el-input v-model="form.bookerId" placeholder="请输入订房人ID" />
        </el-form-item>
        <el-form-item label="服务员ID" prop="serviceStaffId">
          <el-input v-model="form.serviceStaffId" placeholder="请输入服务员ID" />
        </el-form-item>
        <el-form-item label="DJ ID" prop="djId">
          <el-input v-model="form.djId" placeholder="请输入DJ ID" />
        </el-form-item>

        <el-form-item label="订房人进房次数" prop="bookerEntryCount">
          <el-input-number v-model="form.bookerEntryCount" :min="0" placeholder="请输入订房人进房次数" />
        </el-form-item>
        <el-form-item label="服务员进房次数" prop="serviceStaffEntryCount">
          <el-input-number v-model="form.serviceStaffEntryCount" :min="0" placeholder="请输入服务员进房次数" />
        </el-form-item>
        <el-form-item label="DJ进房次数" prop="djEntryCount">
          <el-input-number v-model="form.djEntryCount" :min="0" placeholder="请输入DJ进房次数" />
        </el-form-item>
        <el-form-item label="总金额" prop="totalAmount">
          <el-input-number v-model="form.totalAmount" :precision="2" :step="0.1" :min="0" placeholder="请输入总金额" />
        </el-form-item>
        <el-form-item label="折扣" prop="discount">
          <el-input-number v-model="form.discount" :precision="2" :step="0.1" :min="0" placeholder="请输入折扣" />
        </el-form-item>
        <el-form-item label="服务员工资支付方式" prop="serviceStaffPayment">
          <el-select v-model="form.serviceStaffPayment" placeholder="请选择服务员工资支付方式">
            <el-option label="现金" value="现金" />
            <el-option label="转账" value="转账" />
            <el-option label="自付" value="自付" />
          </el-select>
        </el-form-item>
        <el-form-item label="DJ工资支付方式" prop="djPayment">
          <el-select v-model="form.djPayment" placeholder="请选择DJ工资支付方式">
            <el-option label="现金" value="现金" />
            <el-option label="转账" value="转账" />
            <el-option label="自付" value="自付" />
          </el-select>
        </el-form-item>
        <el-form-item label="业务员工资支付方式" prop="salespersonPayment">
          <el-select v-model="form.salespersonPayment" placeholder="请选择业务员工资支付方式">
            <el-option label="现金" value="现金" />
            <el-option label="转账" value="转账" />
            <el-option label="自付" value="自付" />
          </el-select>
        </el-form-item>

        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="备用字段 ee" prop="ee">
          <el-input v-model="form.ee" placeholder="请输入备用字段 ee" />
        </el-form-item>
        <el-form-item label="备用字段 ff" prop="ff">
          <el-input v-model="form.ff" placeholder="请输入备用字段 ff" />
        </el-form-item>
        <el-form-item label="投诉内容" prop="aa">
          <el-input v-model="form.aa" type="textarea" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="预订业务员组" prop="bb">
          <el-select
            v-model="bbs"
            multiple
            filterable
            placeholder="请选择预订业务员"
            @change="handleGroupNameChange"
          >
            <el-option
              v-for="item in businessUsers"
              :key="item.userId"
              :label="item.userName"
              :value="item.userId"
            />
          </el-select>
        </el-form-item>
      </el-form>

    </el-dialog>
  </div>
</template>

<script>
import { listRoom, getRoom, delRoom, addRoom, updateRoom, flipTable } from "@/api/system/room";
import { listUsersByRole } from "@/api/system/user";

export default {
  name: "Room",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 房间信息表格数据
      roomList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open1: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        area: null,
        price: null,
        status: null,
        groupName: null,
        purpose: null,
        bookerId: null,
        serviceStaffId: null,
        djId: null,
        startTime: null,
        endTime: null,
        bookerEntryCount: null,
        serviceStaffEntryCount: null,
        djEntryCount: null,
        totalAmount: null,
        discount: null,
        serviceStaffPayment: null,
        djPayment: null,
        salespersonPayment: null,
        aa: null,
        bb: null,
        cc: null,
        ee: null,
        ff: null,
        createdAt: null,
        updatedAt: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      
               cc: [
          { required: true, message: "房间名不能为空", trigger: "blur" }
        ]
      },
      businessUsers: [], // 存储业务员列表
      selectedBusinessUsers: [], // 存储选中的业务员ID数组
    };
  },
  created() {
    this.getList();
    this.getBusinessUsers();
  },
  methods: {
    /** 处理价格变化 */
    handlePriceChange(value) {
      if (value === 0 || value === '') {
        this.queryParams.price = null;
      }
    },
    /** 处理价格清除 */
    handlePriceClear() {
      this.queryParams.price = null;
    },
    /** 查询房间信息列表 */
    getList(pagination) {
      this.loading = true;
      // 如果传入了分页参数，更新查询参数
      if (pagination) {
        this.queryParams.pageNum = pagination.page;
        this.queryParams.pageSize = pagination.limit;
      }
      // 确保价格为0时不传该参数
      const params = { ...this.queryParams };
      if (params.price === 0) {
        delete params.price;
      }
      listRoom(params).then(response => {
        this.roomList = response.rows;
        this.total = response.total;
        this.loading = false;
      }).catch(error => {
        this.loading = false;
        this.$modal.msgError("查询失败：" + error);
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      // 设置默认的开始和结束时间
      const today = new Date();
      const tomorrow = new Date(today);
      tomorrow.setDate(tomorrow.getDate() + 1);

      // 设置今天的0点
      today.setHours(0, 0, 0, 0);
      // 设置明天的0点
      tomorrow.setHours(0, 0, 0, 0);

      this.selectedBusinessUsers = []; // 重置选中的业务员
      this.form = {
        id: null,
        area: null,
        price: null,
        status: null,
        groupName: null,
        purpose: null,
        bookerId: null,
        serviceStaffId: null,
        djId: null,
        startTime: today.toISOString(),
        endTime: tomorrow.toISOString(),
        bookerEntryCount: null,
        serviceStaffEntryCount: null,
        djEntryCount: null,
        totalAmount: null,
        discount: null,
        serviceStaffPayment: null,
        djPayment: null,
        salespersonPayment: null,
        aa: null,
        bb: null,
        cc: null,
        ee: null,
        ff: null,
        remark: null,
        createdAt: null,
        updatedAt: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.price = null;  // 确保重置时价格为null
      this.queryParams.pageNum = 1;  // 重置分页到第一页
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加房间信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRoom(id).then(response => {
        this.form = response.data;
        // 如果有groupName，将其转换为数组
        if (this.form.groupName) {
          this.selectedBusinessUsers = this.form.groupName.split(',');
        }
        this.open = true;
        this.title = "修改房间信息";
      });
    },
      /** 修改按钮操作 */
      handleDetail(row) {
      this.reset();
      const id = row.id || this.ids
      getRoom(id).then(response => {
        this.form = response.data;
        // 如果有groupName，将其转换为数组
        if (this.form.groupName) {
          this.selectedBusinessUsers = this.form.groupName.split(',');
        }
        this.open1 = true;
        this.title = "房间详情信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRoom(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRoom(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              // 重置查询条件
              this.resetQuery();
              // 重新获取列表
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除房间信息编号为"' + ids + '"的数据项？').then(function() {
        return delRoom(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/room/export', {
        ...this.queryParams
      }, `room_${new Date().getTime()}.xlsx`)
    },
    /** 获取状态标签 */
    getStatusLabel(status) {
      const statusMap = {
        'available': '可用',
        'booked': '预订',
        'fatai': '发台',
        'inuse': '使用',
        'checkout': '结账',
        'clean': '清洁',
        'union': '联台'
      };
      return statusMap[status] || status;
    },
    /** 获取状态类型 */
    getStatusType(status) {
      const typeMap = {
        'available': 'success',
        'booked': 'primary',
        'fatai': 'warning',
        'inuse': 'primary',
        'checkout': 'danger',
        'clean': 'info',
        'union': 'info'
      };
      return typeMap[status] || '';
    },
    /** 获取支付方式标签 */
    getPaymentLabel(payment) {
      const paymentMap = {
        'cash': '现金',
        'transfer': '转账',
        'other': '其他'
      };
      return paymentMap[payment] || payment;
    },
    // 获取业务员列表
    getBusinessUsers() {
      listUsersByRole(102, null, 1, 1000).then(response => {
        this.businessUsers = response.rows;
      });
    },
    // 处理业务员选择变化
    handleGroupNameChange(value) {
      // 将选中的用户ID用逗号连接
      this.form.groupName = value.join(',');
    },
    // 将用户ID转换为用户名
    getBusinessUserNames(groupName) {
      if (!groupName) return '';
      const userIds = groupName.split(',');
      const userNames = userIds.map(id => {
        const user = this.businessUsers.find(u => u.userId === parseInt(id));
        return user ? user.userName : id;
      });
      return userNames.join(', ');
    },
    // 翻台操作
    handleFlipTable(row) {
      this.$modal.confirm('是否确认翻台房间信息编号为"' + row.id + '"的数据项？').then(function() {
        return flipTable(row.id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("翻台成功");
      }).catch(() => {});
    }
  }
};
</script>
